package cn.study.luckyapp.server;

import cn.study.luckyapp.acceptPrize.command.AcceptPrizeCmdExe;
import cn.study.luckyapp.record.command.RecordUpdateStatusCmdExe;
import cn.study.luckyclient.api.IAcceptPrizeService;
import cn.study.luckyclient.dto.AcceptPrizeAddCmd;
import cn.study.luckyclient.dto.RecordUpdateStatusCmd;
import cn.study.luckyclient.dto.data.AcceptPrizeVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@AllArgsConstructor
public class AcceptPrizeServiceImpl implements IAcceptPrizeService {
    private final RecordUpdateStatusCmdExe recordUpdateStatusCmdExe;
    private final AcceptPrizeCmdExe acceptPrizeCmdExe;
    @Transactional
    @Override
    public AcceptPrizeVo add(AcceptPrizeAddCmd cmd) {
        RecordUpdateStatusCmd recordUpdateStatusCmd = new RecordUpdateStatusCmd();
        recordUpdateStatusCmd.setId(cmd.getRecordId());
        recordUpdateStatusCmd.setState(2);
        recordUpdateStatusCmdExe.execute(recordUpdateStatusCmd);
        return acceptPrizeCmdExe.execute(cmd);
    }
}
